﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MQTT.Server.Host.Controller;
using MQTT.Server.Host.Entity;

namespace MQTT.Server.Host
{
    /// <summary>
    /// WinAddDataNodeTag.xaml 的交互逻辑
    /// </summary>
    public partial class WinAddDataNodeTag : Window
    {

        public string Tag => inputTag.Text;

        private List<DeviceDataTypeEntity> types;
        public DeviceDataTypeEntity DataModel => types.Find(p => p.Name.Equals(selectDataType.Text));
        public WinAddDataNodeTag()
        {
            InitializeComponent();
        }

        private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }

        private void WinAddDataNodeTag_OnLoaded(object sender, RoutedEventArgs e)
        {
            // 获取所有的数据类型
            types = DataController.GetDataTypes();
            var listType = types.Select(p => p.Name).ToList();
            selectDataType.Items = listType;
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(Tag))
            {
                MessageBox.Show("请输入数据标识");
                return;
            }

            if (string.IsNullOrEmpty(selectDataType.Text))
            {
                MessageBox.Show("请选择数据类型");
                return;
            }

            DialogResult = true;
        }
    }
}
